<style>
    .input-readonly{background-color:#eee;}
	.layui-table td, .layui-table th{padding:6px 8px;}
	.layui-form-label{padding:8px 6px;width:96px;}
</style>
<form class="layui-form" action="{:url()}?action=createOrder" method="post" id="editForm">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>订单信息</legend>
	</fieldset>
    <div class="orderform layui-form-item">
    {:FormExt::setInline()}
    {:FormExt::input('订单号', 'client_ordernum', '', '请输入订单号', 'required', 'lay-verify="required"')}
	{:FormExt::input('客户单号', 'ext_id', '', '请输入客户单号', '', 'lay-verify=""')}
    {:FormExt::input('产品sku', 'sku', '', '请输入SKU', 'required', 'lay-verify="required" onBlur="aaa(this.value)"')}
    {:FormExt::select('所属工厂', 'factory_id', '', $factoryKV, '', '')}
    {:FormExt::select('分组', 'group_id', '', ['0' => '请选择']+$groupKV, '', '')}

    {:FormExt::datetime('下单时间', 'create_time', '', '', '选择下单时间', '', 'lay-verify=""')}
    {:FormExt::datetime('交货时间', 'shipment_time', '', '', '选择交货时间', '', 'lay-verify=""')}
    {:FormExt::datetime('采购完成时间', 'caigou_over_time', date('Y-m-d H:i:s'), '', '请选择采购完成时间', '', 'lay-verify=""')}
    {:FormExt::datetime('裁床完成时间', 'caichuang_over_time', date('Y-m-d H:i:s'), '', '请选择裁床完成时间', '', 'lay-verify=""')}
	{:FormExt::datetime('车间完成时间', 'chejian_over_time', date('Y-m-d H:i:s'), '', '请选择裁床完成时间', '', 'lay-verify=""')}
    {:FormExt::radio('是否外发', 'outgo_status', '', ['0' => '否', '2' => '是'], '', '')}
    {:FormExt::select('外发工厂', 'factory_outgo_id', '', ['0' => '请选择']+$factoryOutgoKV, '', '')}
    {:FormExt::input('外发价格', 'outgo_price', '', '请输入外发价格', '', 'lay-verify="mimonumber"')}
    {:FormExt::datetime('外发时间', 'outgo_time', '', '', '请选择外发时间', '', 'lay-verify=""')}
	</div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>尺码件数(<span class="red">必填</span>) -
			<a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-xs size-add"><i class="layui-icon">&#xe654;</i></a>
		</legend>
	</fieldset>
	<div class="layui-form size-list">
		<table class="layui-table">
			<thead>
				<tr>
					<th width="90">选择尺码：</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 0, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 1, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 2, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 3, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 4, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 5, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 6, ''), $sizeNameList)}</th>
					<th>{:Form::select('sizename[]', arrayGet($sizenameArr, 7, ''), $sizeNameList)}</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>
    
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>订单产品信息</legend>
	</fieldset>
	<div class="layui-form-item">
		{:FormExt::setInline()}
        <div class="layui-inline upload" style="width:280px; padding-left:30px;">
            <button type="button" name="upload" class="layui-btn layui-btn-primary layui-upload" lay-type="image" lay-data="{exts:'jpg|png|gif|bmp|jpeg', accept:'images'}">请上传产品图</button>
            <input type="hidden" class="upload-input" name="pic" value="{:arrayGet($formData, 'pic', '')}">
            {if condition="arrayGet($formData, 'pic', '') != ''"}
                <img src="{:arrayGet($formData, 'pic', '')}" style="display:inline-block;border-radius:5px;border:1px solid #ccc" width="36" height="36">
            {else /}
                <img src="" style="display:none;border-radius:5px;border:1px solid #ccc" width="36" height="36">
            {/if}
        </div>
		{:FormExt::input('图片地址', 'pic_url', '', '图片地址', '', '')}

        <div class="layui-inline">
            <label class="layui-form-label">SKU</label>
            <div class="layui-input-inline">
              <input type="text"  value="" autocomplete="off" class="layui-input sku_copy" disabled="disabled" name="sku_copy">
            </div>
        </div>

	    {:FormExt::input('售价', 'price', '', '请输入售价', '', 'lay-verify="mimonumber"')}
	    
	    {if condition="arrayGet($formData, 'sku', '') != ''"}
	    	{:FormExt::input('款式', 'style_name', '', '', '', '')}
	    	{:FormExt::input('是否新款', 'is_new', '', '', '', '')}
	    {else/}
	    	{:FormExt::input('款式', 'style_name', '', '', '', '')}
	    {/if}
	    
	    {:FormExt::select('品类', 'sku_type', '', ['针织' => '针织', '梭织' => '梭织'], '', '', 'lay-verify=""')}
	    {:FormExt::select('裁剪方式', 'caichuang_position', '', $caichuangPosition, '', '', 'lay-verify=""')}
	    {if condition="arrayGet($formData, 'sku', '') != ''"}{:FormExt::input('面料种类', 'a_material_name', '', '', '', '')}{/if}
	    {:FormExt::select('大烫', 'off_pressing_level', '', $processLevel, '', '', 'lay-verify=""')}
        <div style="display:none;">
            {:FormExt::select('二次工艺A-'.arrayGet($formData, 'special_process_a_name', '无'), 'special_process_a_level', '', $processLevel, '', '', 'lay-verify=""')}
            {:FormExt::select('二次工艺B-'.arrayGet($formData, 'special_process_b_name', '无'), 'special_process_b_level', '', $processLevel, '', '', 'lay-verify=""')}
            {:FormExt::select('二次工艺C-'.arrayGet($formData, 'zj_name', '无'), 'zj_level', '', $processLevel, '', '', 'lay-verify=""')}</div>
            
            {:FormExt::input('外发倍率', 'outsource_per', '', '', '', '')}
            {:FormExt::input('外发价格%', 'outsource_perb', '', '', '', '')}
            {:FormExt::input('加工费', 'cost', '', '请输入加工费', '', '')}
            {:FormExt::input('加工费小计', 'cost_little', '', '请输入加工费小计', 'border-none', '')}
            {:FormExt::input('加工费倍率', 'cost_scale', '', '请输入加工费倍率', 'border-none', '')}
            {:FormExt::input('外发价', 'outsource_price', '', '请输入外发价', 'red', 'lay-verify="mimonumber"')}
            {:FormExt::input('车位价(<strong></strong>)', 'chewei_price', '', '请输入车位价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('打边价', 'sixian_price', '', '请输入打边价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('冚车价', 'zhuanji_price', '', '请输入冚车价', '', 'lay-verify="mimonumber"')}
        <div style="display:none;">
            {:FormExt::input('专机费名称', 'zj_name', '', '请输入专机费名称', '', 'lay-verify=""')}
            {:FormExt::input('专机费数量', 'zj_count', '', '请输入专机费数量', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('专机费单价', 'zj_unitprice', '', '请输入专机费单价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('专机费总价', 'zj_price', '', '请输入专机费总价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺A名称', 'special_process_a_name', '', '请输入工艺A名称', '', 'lay-verify=""')}
            {:FormExt::input('工艺A数量', 'special_process_a_count', '', '请输入工艺A数量', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺A单价', 'special_process_a_unitprice', '', '请输入工艺A单价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺A总价', 'special_process_a_price', '', '请输入工艺A总价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺B名称', 'special_process_b_name', '', '请输入工艺B名称', '', 'lay-verify=""')}
            {:FormExt::input('工艺B数量', 'special_process_b_count', '', '请输入工艺B数量', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺B单价', 'special_process_b_unitprice', '', '请输入工艺B单价', '', 'lay-verify="mimonumber"')}
            {:FormExt::input('工艺B总价', 'special_process_b_price', '', '请输入工艺B总价', '', 'lay-verify="mimonumber"')}
    <!--	    {:FormExt::select('复色指定工厂', 'factory_id', '', $factoryKV, '', '', 'lay-verify=""')}-->
            {:FormExt::input('二次工艺工厂', 'special_process_factory_name', '', '请输入二次工艺工厂', '', 'lay-verify=""')}
            {:FormExt::select('二次工艺地区', 'fabrics_process_addr', '0', ['0' => '广州江西均可做', '1' => '只广州可做'], '', '', 'lay-verify=""')}
            {:FormExt::select('面辅加工难度', 'fabrics_process_complexity', '', ['0' => '简', '1' => '易','2'=>'难'], '', '', 'lay-verify=""')}
        </div>

	</div>
	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>材料<span class="red">(必填)</span> -  <a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-xs material-add"><i class="layui-icon">&#xe654;</i></a></legend>
	</fieldset>
	<div class="layui-form material-list">
		<table class="layui-table">
			<thead>
				<tr>
					<th>物料名称</th>
					<th>物料SKU</th>
					<th>型号</th>
					<th>色号</th>
					<th>颜色</th>
					<th>客户用量</th>
					<th>{:config("base.company_short_name")}用量</th>
					<th>精准用量</th>
                    <th width="70px">纸筒</th>
                    <th width="70px">空差</th>
					<th>客户单价</th>
					<th>单价</th>
					<th>客户布封</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{foreach $smList as $v}
				<tr>
					<td>{$v['mInfo']['name']}</td>
					<td>{$v['mInfo']['material_sku']}</td>
					<td>{$v['mInfo']['model']}</td>
					<td>{$v['mInfo']['colornum']}</td>
					<td>{$v['mInfo']['color']}</td>
					<td><input type="text" name="customer_dosage[{$v['mInfo']['id']}]" value="{$v['customer_dosage']}" autocomplete="off" class="layui-input" lay-verify="required|mimonumber"></td>
					<td><input type="text" name="material_dosage[{$v['mInfo']['id']}]" value="{$v['material_dosage']}" autocomplete="off" class="layui-input" lay-verify="required|mimonumber"></td>
					<td><input type="text" name="accurate_dosage[{$v['mInfo']['id']}]" value="{$v['accurate_dosage']}" autocomplete="off" class="layui-input" lay-verify="number"></td>
                    <td><input type="text" name="tube_weight[{$v['mInfo']['id']}]" value="{$v['mInfo']['customer_weight_page']}" autocomplete="off" class="layui-input" lay-verify="mimonumber"></td>
                    <td><input type="text" name="diff_meters[{$v['mInfo']['id']}]" value="{$v['mInfo']['diff_length']}" autocomplete="off" class="layui-input" lay-verify="mimonumber"></td>
					<td>{$v['customer_price']}</td>
					<td>{$v['mInfo']['price']}</td>
					<td>{$v['mInfo']['fabric_width']}</td>
					<td><a href="javascript:void(0)" class="layui-btn layui-btn-danger layui-btn-sm btn-del"><i class="layui-icon">&#xe640;</i></a></td>
				</tr>
				{/foreach}
			</tbody>
		</table>
	</div>
	
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>其它备注		</legend>
	</fieldset>
    <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">生产工艺</label>
	    <div class="layui-input-block" style="margin-left:120px;">
	      <textarea placeholder="请输入内容" name="process" class="layui-textarea">{:arrayGet($formData, 'process', '')}</textarea>
	    </div>
	</div>
    <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">裁剪要求</label>
	    <div class="layui-input-block" style="margin-left:120px;">
	      <textarea placeholder="请输入内容" name="cutting_requirements" class="layui-textarea">{:arrayGet($formData, 'cutting_requirements', '')}</textarea>
	    </div>
	</div>
	<div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">车间要求</label>
	    <div class="layui-input-block" style="margin-left:120px;">
	      <textarea placeholder="请输入内容" name="workshop_requirements" class="layui-textarea">{:arrayGet($formData, 'workshop_requirements', '')}</textarea>
	    </div>
	</div>
	<div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">尾部要求</label>
	    <div class="layui-input-block" style="margin-left:120px;">
	      <textarea placeholder="请输入内容" name="tail_requirements" class="layui-textarea">{:arrayGet($formData, 'tail_requirements', '')}</textarea>
	    </div>
	</div>
	
	<div class="pop-bottom-bar">
    	<input type="hidden" class="field-id" name="id">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: false}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>
<script id="sizeTpl" type="text/html">
	{foreach $partArr as $k => $v}
	<tr>
		<td class="layui_tool_showSelect_{$k}">
		</td>
		<td><input type="text" name="measurement[]" value="{:arrayGet($measurementArr, $k, '')}" autocomplete="off" class="layui-input" lay-verify=""></td>
		<td>
			<a href="javascript:void(0)" onclick="onclickTiaoSize(this)" class="hisi-iframe layui-btn layui-btn-sm " hisi-data="{width: '860px', height: '90%'}" >跳码设置</a>
			<a  href="javascript:void(0)" onclick="onclickTiaoSizeRun(this)" class="layui-btn layui-btn-sm "  >生效</a>
		</td>
		<td class="tiaoSizeContent">-----</td>
		<td><input type="text" name="size[0][]" value="{:arrayGet(arrayGet($sizeArr, 0, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[1][]" value="{:arrayGet(arrayGet($sizeArr, 1, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[2][]" value="{:arrayGet(arrayGet($sizeArr, 2, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[3][]" value="{:arrayGet(arrayGet($sizeArr, 3, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[4][]" value="{:arrayGet(arrayGet($sizeArr, 4, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[5][]" value="{:arrayGet(arrayGet($sizeArr, 5, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[6][]" value="{:arrayGet(arrayGet($sizeArr, 6, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><input type="text" name="size[7][]" value="{:arrayGet(arrayGet($sizeArr, 7, []), $k, '0')}" autocomplete="off" class="layui-input" lay-verify="number"></td>
		<td><a href="javascript:void(0)" class="layui-btn layui-btn-danger layui-btn-sm btn-del"><i class="layui-icon">&#xe640;</i></a></td>
	</tr>
	{/foreach}
</script>
{include file="system@block/layui" /}
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script>
    var formData = {:json_encode($formData)};
    var partList = {:json_encode($partList)};
	var partListAll = {:json_encode($partListAll)};
	var xm_select_data = {:json_encode($xm_select_data)};
	var partArrInit = {:json_encode($partArr)};
	var tiaoData=[];
	var allTiaoData={};
    layui.use(['form', 'func', 'jquery', 'upload', 'layer', 'laydate', 'tool'], function() {
        $ = layui.jquery;
        var form = layui.form;
		var laytpl = layui.laytpl,laydate=layui.laydate ,table = layui.table;
        var upload = layui.upload;
        var layer = layui.layer;
		var laydate = layui.laydate;
        layui.func.assign(formData);
        /* 绑定多个日期控件 */
        $('.layui-date').each(function(i) {
            var t = $(this), option = {
                elem: this,
                type: t.attr('laydate-type'),
                mark: {'{:$today}':''},
                trigger: 'click'
            };

            laydate.render(option);
        });
		     
        upload.render({
            elem: '.layui-upload',
            url: '{:url("system/annex/upload?thumb=no&water=no&full_path=true")}'
            ,method: 'post'
            ,before: function(input) {
                layer.msg('文件上传中...', {time:3000000});
            },done: function(res, index, upload) {
                var obj = this.item;
                if (res.code == 0) {
                    layer.msg(res.msg);
                    return false;
                }
                layer.closeAll();
                var input = $(obj).parents('.upload').find('.upload-input');
                if ($(obj).attr('lay-type') == 'image') {
                    input.siblings('img').attr('src', res.data.file).show();
                }
                input.val(res.data.file);
            }
        });
        
        var reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
        
        form.verify({
        	mimonumber: function(value, item){
        	    if (value=='') return '';
        	    if(! reg.test(value)){
        	    	return '只能填写数字';
        	    }
        	}
        });
        
        // 添加物料
        $(document).on('click', '.material-add',function(){
        	layer.open({
        		  type: 2,
        		  title:"物料选择",
        		  area: ['70%', '70%'],
        		  anim: parseInt(Math.random()*(6+1),10),
        		  content: '{:url("mp/material/selectItem")}'
        	}); 
		});

		// 添加尺码部位
		$(document).on('click', '.size-add',function(){
			var html='<tr>';
			html += '<td class="tiaoSizeContent">下单件数--></td>';
			html += '<td><input type="text" name="size[0][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[1][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[2][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[3][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[4][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[5][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[6][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><input type="text" name="size[7][]" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
			html += '<td><a href="javascript:void(0)" class="layui-btn layui-btn-danger layui-btn-sm btn-del"><i class="layui-icon">&#xe640;</i></a></td>';
			html += '<tr>';
			$('.size-list table tbody').append(html);
		});
		//尺码部位-初始化
		var content = laytpl($('#sizeTpl').html()).render({data:{}});
		$('.size-list table tbody').append(content);
		$.each(partArrInit, function(i, n){
			var  html = layui.tool.showSelect('part[]', n, partList,'','','lay-filter="partListSelect" onchange="partListSelect(this)" ');
			$('.layui_tool_showSelect_'+i).html(html);
		});
		// 选择模板--尺码部位
		$(document).on('click', '.size-select-template',function(){
			layer.open({
				type: 2,
				title:"物料选择",
				area: ['70%', '70%'],
				anim: parseInt(Math.random()*(6+1),10),
				content: '{:url("mp/template/selectItem")}'
			});
		});

		// 删除条目
        $(document).on('click', '.btn-del',function(){
			$(this).parents('tr').remove();
		});
        // 智能修改  加工费倍率 * 加工费小计 = 加工费
		$(document).on('change', '[name="cost_scale"]',function(){
			var temp= parseFloat( $('[name="cost_scale"]').val());
			var temp2= parseFloat( $('[name="cost_little"]').val());
			$('[name="cost"]').val((temp*temp2).toFixed(2));
		});
		$(document).on('change', '[name="cost_little"]',function(){
			var temp= parseFloat( $('[name="cost_scale"]').val());
			var temp2= parseFloat( $('[name="cost_little"]').val());
			$('[name="cost"]').val((temp*temp2).toFixed(2));
		});
		// 智能修改  专机费数量 * 专机费单价 = 专机费总价
		$(document).on('change', '[name="zj_count"]',function(){
			var temp= parseFloat( $('[name="zj_count"]').val());
			var temp2= parseFloat( $('[name="zj_unitprice"]').val());
			$('[name="zj_price"]').val((temp*temp2).toFixed(2));
		});
		$(document).on('change', '[name="zj_unitprice"]',function(){
			var temp= parseFloat( $('[name="zj_count"]').val());
			var temp2= parseFloat( $('[name="zj_unitprice"]').val());
			$('[name="zj_price"]').val((temp*temp2).toFixed(2));
		});
		// 智能修改  工艺A单价 * 工艺A数量 = 工艺A总价
		$(document).on('change', '[name="special_process_a_count"]',function(){
			var temp= parseFloat( $('[name="special_process_a_count"]').val());
			var temp2= parseFloat( $('[name="special_process_a_unitprice"]').val());
			$('[name="special_process_a_price"]').val((temp*temp2).toFixed(2));
		});
		$(document).on('change', '[name="special_process_a_unitprice"]',function(){
			var temp= parseFloat( $('[name="special_process_a_count"]').val());
			var temp2= parseFloat( $('[name="special_process_a_unitprice"]').val());
			$('[name="special_process_a_price"]').val((temp*temp2).toFixed(2));
		});
		// 智能修改  工艺B单价 * 工艺B数量 = 工艺B总价
		$(document).on('change', '[name="special_process_b_count"]',function(){
			var temp= parseFloat( $('[name="special_process_b_count"]').val());
			var temp2= parseFloat( $('[name="special_process_b_unitprice"]').val());
			$('[name="special_process_b_price"]').val((temp*temp2).toFixed(2));
		});
		$(document).on('change', '[name="special_process_b_unitprice"]',function(){
			var temp= parseFloat( $('[name="special_process_b_count"]').val());
			var temp2= parseFloat( $('[name="special_process_b_unitprice"]').val());
			$('[name="special_process_b_price"]').val((temp*temp2).toFixed(2));
		});
    });

	function getSizeListTemplate(id) {
		$.ajax({
			type: "post",
			url: "{:url('mp/Template/getInfoHtml')}"+"?id="+id,
			data: {},
			dataType: "json",
			success: function (res) {
				$('.size-list').html(res.data);
				layui.form.render();
				var laytpl = layui.laytpl,laydate=layui.laydate ,table = layui.table;
				//尺码部位-初始化
				var content = laytpl($('#sizeTpl').html()).render({data:{}});
				$('.size-list table tbody').append(content);
				$.each(partArrInit, function(i, n){
					var  html = layui.tool.showSelect('part[]', n, partList,'','','lay-filter="partListSelect" onchange="partListSelect(this)" ');
					$('.layui_tool_showSelect_'+i).html(html);
				});
				tiaoSizeContentSet(1);
			}
		});
	}

	// 部位尺码->添加=》部位 选择后设置 量法  --- 并显示跳码规则
	function partListSelect(obj) {
		//2,显示跳码规则
		tiaoSizeContentSet();
		//1,部位 选择后设置 量法
		var temp='';
		$.each( partListAll, function(i, n){
			if($(obj).val()==n.name){
				temp=n.name_ext;
				return ;
			}
		});
		$(obj).parent().parent().find('[name="measurement[]"]').val(temp);
	}

	//跳码设置
	function onclickTiaoSize(obj) {
		var  rows = $(obj).parent().parent().prevAll().length + 1; //行号
		var part=$(obj).parent().parent().find('[name="part[]"]').val();
		$(obj).attr('href',"{:url('mp/Template/tiaoNumEdit')}?tr_num="+rows+'&part='+part);
		$(obj).trigger('click');
	}
	//跳码设置--子函数
	function tiaoNumEdit(d) {
		tiaoData=d;
		allTiaoData[tiaoData.tr_num]=tiaoData;
		//1，自动选择码
		if(tiaoData.selected_type==1){
			th_select_set();
		}
		//2,显示跳码规则
		tiaoSizeContentSet(1);
	}

	//1，自动选择码
	function th_select_set() {
		//计算出所要选择的码
		var arr1 = [];
		for (var i = 0; i < 5; i++) {
			var temp = tiaoData['xm_select_size[]'][i];
			var arr2 = temp.split(',');
			arr1 = arr1.concat(arr2);
		}
		var resval=[];
		$.each(xm_select_data, function(i, n){
			$.each(arr1, function(i2, n2){
				if(n2==n.value){
					resval.push(n.name);
				}
			});
		});
		resval=uniq(resval);
		//进行选择设置 0-7  $('.size-list').find("div.layui-form-select:eq(1)").find('dl').find('dd[lay-value="XL"]').click();
		for(var i = 0; i < resval.length; i++){
			$('.size-list').find("div.layui-form-select:eq("+i+")").find('dl').find('dd[lay-value="'+resval[i]+'"]').click();
		}
	}

	/**
	 * 最简单数组去重法
	 */
	function uniq(array){
		var temp = []; //一个新的临时数组
		for(var i = 0; i < array.length; i++){
			if(temp.indexOf(array[i]) == -1){
				temp.push(array[i]);
			}
		}
		return temp;
	}
	//跳码生效
	var sizeRuntemp={};
	function onclickTiaoSizeRun(obj) {
		//1,获跳码规则
		var temp_row = $(obj).parent().parent().prevAll().length + 1; //行号
		sizeRuntemp.row=temp_row;
		if(typeof(allTiaoData[temp_row])=="undefined"){
			layer.msg('没设置跳码规则', {icon: 2,anim: 6});
			return false;
		}
		//2,检查  头部选择的码信息，与，本行有基码大于0 才生效
		//2.1,检查  头部选择的码信息
		var head_select=[];
		for(var i = 0; i < 8; i++){
			var temp=$('.size-list').find('[name="sizename[]"]:eq('+i+')').val();
			if(temp!=''){
				head_select.push(temp);
			}
		}
		sizeRuntemp.head_select=head_select;
		if( sizeRuntemp.head_select.length==0){
			layer.msg('没选择尺码', {icon: 2,anim: 6});
			return false;
		}
		//2.2，本行有基码大于0  $('.size-list').find('tr:eq(1)').find('[name="size[1][]"]').val();
		var size_tr=[];
		var flag=0;
		for(var i = 0; i <= 7; i++){
			var temp=parseFloat( $('.size-list').find('tr:eq('+temp_row+')').find('[name="size['+i+'][]"]').val());
			size_tr.push(temp);
			if(temp>0){
				flag=temp;
			}
		}
		sizeRuntemp.size_tr=size_tr;
		if(flag==0){
			layer.msg('些行基码都为0', {icon: 2,anim: 6});
			return false;
		}
		//3,综合 规则 码  基码 计算出 基码并设置
		set_size_data();
	}
	/**
	 * 逻辑计算顺序： 1实际顺序  2位置数   3实际规则   4实际结果  5显示结果
	 * 主要参数 xm_select_data  allTiaoData  sizeRuntemp
	 * @param obj
	 */
	var temp_data={
		wei:{}
		,rule:{}
		,temp_res:[]
	};
	function set_size_data() {
		//1,实际顺序 xm_select_data 的data-order就是了，不用计算了
		//2,位置数
		temp_data.wei={};
		$.each(sizeRuntemp.size_tr, function(i, n){
			if( ! $.isEmptyObject(temp_data.wei)){
				return false;
			}
			if( n >0){
				$.each(sizeRuntemp.head_select, function(i2, n2){
					if(i2==i){
						temp_data.wei.key=i;
						temp_data.wei.size_tr=n;
						temp_data.wei.head_select=n2;
						return false;
					}
				});
			}
		});
		$.each(xm_select_data, function(i, n){
			if(n.name==temp_data.wei.head_select){
				xm_select_data[i]['now_start_data']=xm_select_data[i]['now_data']=temp_data.wei.size_tr;
				temp_data.wei.data_order=n['data-order'];
			}
		});
		//3,实际规则
		//3.1, 找出 最大 最小 跳码
		temp_data.temp_res=[];
		$.each(allTiaoData[sizeRuntemp.row]['xm_select_size[]'], function(i, n){
			if(n!=''){
				//找出 最大 最小 跳码
				var temp_res={
					min:12345678,
					max:-1,
					tiao_num: parseFloat( allTiaoData[sizeRuntemp.row]['tiao_num[]'][i])
				};
				var data_order=[];
				var temp=n.split(',');

				$.each(temp, function(i2, n2){
					$.each(xm_select_data, function(i3, n3){
						if(n2==n3.value){
							data_order.push(n3['data-order']);
							return false;
						}
					});
				});
				$.each(data_order, function(i2, n2){
					if(parseInt(n2)<temp_res.min){
						temp_res.min=parseInt(n2);
					}
					if(parseInt(n2)>temp_res.max){
						temp_res.max=parseInt(n2);
					}
				});
				temp_data.temp_res.push(temp_res);
			}
		});
		//3.2, 设置实际规则 到 xm_select_data 里 data-add data-del
		$.each(xm_select_data, function(i2, n2){
			xm_select_data[i2]['data-add']=12345678;
			xm_select_data[i2]['data-del']=12345678;
		});
		$.each(temp_data.temp_res, function(i, n){
			$.each(xm_select_data, function(i2, n2){
				if(n2['data-order']>=n.min && n2['data-order']<=n.max){
					if(n2['data-order'] < n.max) xm_select_data[i2]['data-add']=n.tiao_num;
					if(n2['data-order'] > n.min) xm_select_data[i2]['data-del']=n.tiao_num;
				}
			});
		});
		//4,实际结果
		//4.1,加码生效
		$.each(xm_select_data, function(i, n){
			if(temp_data.wei.data_order <n['data-order']){
				xm_select_data[i]['now_data']= xm_select_data[i-1]['now_data']+ xm_select_data[i-1]['data-add'];
			}
		});
		//4.2,减码生效
		xm_select_data.reverse();
		$.each(xm_select_data, function(i, n){
			if(temp_data.wei.data_order > n['data-order']){
				xm_select_data[i]['now_data']= xm_select_data[i-1]['now_data']- xm_select_data[i-1]['data-del'];
			}
		});
		xm_select_data.reverse();
		//5,显示结果
		$.each(sizeRuntemp.head_select, function(i, n){
			$.each(xm_select_data, function(i2, n2){
				if(n2.name==n){
					if(n2['now_data']<10000000){
						$('.size-list').find('tr:eq('+sizeRuntemp.row+')').find('[name="size['+i+'][]"]').val(n2['now_data'].toFixed(0));
					}
				}
			});
		});
	}

	//显示跳码规则
	var allPartTiao={};
	tiaoSizeContentSet(1);
	function tiaoSizeContentSet(flag=0) {
		if(flag==1){
			$.ajax({
				type: "POST",
				url: "{:url('mp/Template/allPartTiao')}",
				data: $("#form33").serialize(),
				dataType:"json",
				success: function(res){
					allPartTiao=res.data;
					tiaoSizeContentSet_real();
				}
			});
		}else{
			tiaoSizeContentSet_real();
		}
	}
	function aaa(val){
		$(".sku_copy").val(val);
	}
	function tiaoSizeContentSet_real() {
		$('.size-list').find('[name="part[]"]').each(function(i100){
			var temp=$(this).val();
			var _this=this;
			$.each(allPartTiao, function(i, n){
				if(n.name==temp){
					//1,显示跳码规则
					if( n.tiaoSizeContent.length==0){
						$(_this).parent().parent().find('.tiaoSizeContent').html('-----');
					}else{
						var html='';
						$.each( n.tiaoSizeContent, function(i2, n2){
							html+=n2.min_name+'-'+n2.max_name+':'+n2.tiao_num +"<br>";
						});
						$(_this).parent().parent().find('.tiaoSizeContent').html(html);
					}
					//2,跳码规则设置
					var tr_num = $(_this).parent().parent().prevAll().length + 1; //行号
					n.ext0.tr_num=tr_num+'';
					n.ext0.part=n.name;
					n.ext0['xm_select_size[]']=n.ext0.xm_select_size;
					n.ext0['tiao_num[]']=n.ext0.tiao_num;
					allTiaoData[tr_num]=n.ext0;
				}
			});
		});
	}
</script>